package cuppics;

import org.junit.Test;

public class Prj27 {

	
	/**
	 * 
	 */
	@Test
	public void test(){
		int[] ab = Calculator.calculate();
		System.out.println(ab[0] * ab[1]);
	}
	
	public static class Calculator{
		
		
		public static  int[] calculate(){
			
			int maxAId = -999;
			int maxBId = -999;
			int maxCount = -1;
			
			for( int i = -999 ; i <= 999 ; i ++){
				for( int j = -999; j <= 999; j ++){
							
					int k = 0;
					for(; ;){
						int val = calculateNum(i, j , k);
						if( isPrime(val)){
							k ++;
						}else{
							break;
						}
					}
					if( k > maxCount){
						maxCount = k;
						maxAId = i;
						maxBId = j;
					}
				}
			}
			
			System.out.println("maxCount=" + maxCount + ",a=" + maxAId + ",b=" + maxBId);
			
			return new int[]{ maxAId, maxBId};
		}
		
		
		public static int calculateNum(int a, int b, int n){
			return n * n + a * n + b;
		}
		
		public static boolean isPrime( int num){
			
			if( num <= 1){
				return false;
			}
			
			if( num == 2 || num == 3){
				return true;
			}
			
			
			for( int i = 2; i <= Math.sqrt(num); i ++){
				if( num % i == 0){
					return false;
				}
			}
			
			
			return true;
			
			
		}
	}
	
}
